		TITLE	CVSTUFF - Copyright (c) SLR Systems 1994

		INCLUDE	MACROS
		INCLUDE	MODULES
		INCLUDE	SEGMENTS
		INCLUDE	CVTYPES


		PUBLIC	CODEVIEW_HERE,CV_INDEX_HDR_SIZE,CV_MODULES_ALL,CV_TARG_TABLE,CV_TYPES_TYPE,CV_LOCALS_TYPE,CV_MODULE
		PUBLIC	CV_LINNUMS,CV_PUBLICS,CV_INDEX_SIZE,CV_LIBRARY_TYPE,CV_SEGTBL,CV_FINAL_HIGH_PARA,CV_DWORD_ALIGN
		PUBLIC	CV_PUBLICS_ALL,CV_GLOBALS_ALL,CV_TYPES_ALL,CV_STATICS_ALL,CV_FILES_ALL,CV_PUB_TXT_OFFSET,CV_PUB_SYMBOL_ID


		EXTERNDEF	FIX2_TARG_TABLE_CV:DWORD,FIX2_TARG_TABLE_NORMAL:DWORD,FIX2_TARG_TABLE_CV32:DWORD


		.DATA

		EXTERNDEF	CV_TEMP_RECORD:BYTE,FIX2_SEG_TYPE:BYTE

		EXTERNDEF	CV_INDEX_BLK_PTR:DWORD,CV_INDEX_TABLE:DWORD,OPTI_STOSD_SIZE:DWORD,CURNMOD_GINDEX:DWORD
		EXTERNDEF	FIX2_TARG_TABLE:DWORD,CV_GTYPE_HASH_LOG:DWORD,LAST_CV_MODULE_GINDEX:DWORD,LOC_10:DWORD
		EXTERNDEF	GSYM_HASH_LOG:DWORD,SSYM_HASH_LOG:DWORD,HIGH_WATER:DWORD,FINAL_HIGH_WATER:DWORD,CV_HEADER_LOC:DWORD
		EXTERNDEF	BYTES_SO_FAR:DWORD,CV_INDEX_PTR:DWORD,FIX2_SM_LEN:DWORD,FIX2_SM_START:DWORD

		EXTERNDEF	MAPLINES_OK_SEM:QWORD,MODULE_GARRAY:STD_PTR_S,CV_STATICSYM_GARRAY:STD_PTR_S

		EXTERNDEF	CV_FINAL_HIGH_PARA:DWORD,OUT_FLUSH_SEGMOD:DWORD


		.CODE	PASS2_TEXT

		EXTERNDEF	_cv_linnums_4:PROC
		EXTERNDEF	CV_INDEX_ANOTHER_BLOCK:PROC,MOVE_EAX_TO_EDX_FINAL:PROC,CV_LINNUMS_3:PROC,CV_LINNUMS_4:PROC
		EXTERNDEF	CV_PUBLICS_3:PROC,CV_PUBLICS_4:PROC,CV_MODULE_3:PROC,CV_MODULES_ALL_4:PROC,CV_SEGTBL_4:PROC
		EXTERNDEF	LOC_10_PROT:PROC,FINAL_HIGH_PARA:PROC,CV_MODULE_4:PROC,RELEASE_DSBX:PROC,CV_TYPES_ALL_4:PROC
		EXTERNDEF	_cv_dword_align_rtn:proc,ALLOW_LINNUMS_MAP:PROC,SELECT_CV4_OUTPUT:PROC,CV_PUBLICS_ALL_4:PROC
		EXTERNDEF	PROCESS_CV_TYPES:PROC,PROCESS_CV_SYMBOLS:PROC,PROCESS_CV_SYM1_SYMBOLS:PROC
		EXTERNDEF	WRITE_CV_INDEX:PROC,FLUSH_EAX_TO_FINAL:PROC
		EXTERNDEF	GET_NEW_LOG_BLK:PROC,INIT_PARALLEL_ARRAY:PROC,CV_GLOBALS_ALL_4:PROC,CV_STATICS_ALL_4:PROC
		EXTERNDEF	NEW_DERIV_BLK_INIT:PROC,CV_FILES_ALL_4:PROC,ALLOW_XREF_MAP:PROC


CODEVIEW_HERE	PROC
		;
		;
		;
		BITT	CV_4_TYPE
		MOV	ESI,OFF CV3_LIST
		JZ	L82$
		CALL	SELECT_CV4_OUTPUT
		MOV	ESI,OFF CV4_LIST
if	fg_cvpack
		BITT	CVPACK_FLAG
		JZ	L815$
		MOV	ESI,OFF CV4_PACKED_LIST
L815$:
endif

L82$:
		MOV	EDI,OFF CV_TABLES
		MOV	ECX,CV_TABLES_LEN/4

		REP	MOVSD

if	fg_pe OR fg_dosx
		BITT	OUTPUT_32BITS
		JZ	L825$
		MOV	CV_PUB_TXT_OFFSET,12
		MOV	CV_PUB_SYMBOL_ID,203H
L825$:
endif
		MOV	EAX,CV_DATA_PTR
		MOV	OUT_FLUSH_SEGMOD,EAX

		CALL	CV_FINAL_HIGH_PARA
		XOR	EAX,EAX

		RESS	EXEPACK_SELECTED,AL
if	fg_winpack
		RESS	WINPACK_SELECTED,AL
		RESS	SEGPACK_SELECTED,AL
		RESS	SEGPACK_SEGMENT,AL
endif
		RESS	EXEPACK_BODY,AL
		RESS	PACKING_RELOCS,AL
		RESS	CHAINING_RELOCS,AL

		MOV	HIGH_WATER,EAX
		MOV	CURNMOD_GINDEX,EAX
if	fg_cv
		SETT	DOING_DEBUG
endif
		MOV	LAST_CV_MODULE_GINDEX,EAX		;NO MODULES YET.
		CALL	ALLOW_LINNUMS_MAP		;DO LINENUMBERS IN PARALLEL
		CALL	ALLOW_XREF_MAP
		;
		;SET STUFF BASED ON CODEVIEW TYPE
		;
		MOV	EAX,CV_TARG_TABLE
if	fg_pe
		BITT	OUTPUT_PE
		JZ	L85$
		MOV	EAX,OFF FIX2_TARG_TABLE_CV32
L85$:
endif
		MOV	FIX2_TARG_TABLE,EAX
		;
		;EXE_OUT_POSITION IS CODEVIEW_HEADER_ADDRESS
		;
		MOV	EAX,FINAL_HIGH_WATER
		MOV	CV_HEADER_LOC,EAX

		MOV	BYTES_SO_FAR,8
		;
		;SET UP BLOCK AND POINTER FOR STORING INDEX ENTRIES
		;
		MOV	CV_INDEX_BLK_PTR,OFF CV_INDEX_TABLE

		CALL	CV_INDEX_ANOTHER_BLOCK
		MOV	EAX,CV_INDEX_HDR_SIZE		;2 FOR CV 0 & 2, 16 FOR 5 & 7
		ADD	CV_INDEX_PTR,EAX		;LEAVE ROOM FOR INDEX COUNT..
		;
		;OUTPUT ALL MODULE RECORDS AND THEIR INDEX ENTRIES
		;
		CALL	CV_MODULES_ALL			;RET FOR 0 & 2, ACTUAL FOR 5 & 7

if	fg_cvpack
		BITT	CVPACK_FLAG
		JZ	RETT
		CALL	GET_NEW_LOG_BLK

		MOV	GSYM_HASH_LOG,EAX
		MOV	EDI,EAX

		MOV	ECX,PAGE_SIZE/4
		XOR	EAX,EAX

		REP	STOSD

		CALL	GET_NEW_LOG_BLK
		MOV	SSYM_HASH_LOG,EAX
		MOV	EDI,EAX
		MOV	ECX,PAGE_SIZE/4
		XOR	EAX,EAX
		REP	STOSD

		CALL	GET_NEW_LOG_BLK

		MOV	CV_GTYPE_HASH_LOG,EAX
		MOV	EDI,EAX

		MOV	ECX,PAGE_SIZE/4
		XOR	EAX,EAX

		REP	STOSD

		CALL	NEW_DERIV_BLK_INIT

endif

		RET

CODEVIEW_HERE	ENDP

RETT:
		RET

CV_DATA_FLUSH	PROC
		;
		;
		;
		MOV	EAX,FIX2_SM_LEN
		MOV	ECX,FIX2_SM_START

		SUB	EAX,ECX
		JZ	L9$			;SKIP IF ZERO LENGTH
if	fg_cvpack
		GETT	CL,CVPACK_FLAG
		MOV	DL,FIX2_SEG_TYPE

		OR	CL,CL
		JZ	L6$

		BITT	CV_SYM1_TYPE		;Test for Symantec format output
                JNZ     L4$

		AND	DL,MASK SEG_CV_TYPES1
		JZ	L3$

		CALL	PROCESS_CV_TYPES
		JMP	L9$

L3$:
		CALL	PROCESS_CV_SYMBOLS
		JMP	L9$

L4$:
		AND	DL,MASK SEG_CV_TYPES1
		JZ	L5$
		;
		; For now, Ignore any $$TYPES sections if Symantec format output
		;
		JMP	L9$

L5$:
		CALL	PROCESS_CV_SYM1_SYMBOLS
		JMP	L9$
endif

L6$:
		PUSH	EAX
		CALL	FLUSH_EAX_TO_FINAL

		POP	ECX
		MOV	AL,FIX2_SEG_TYPE

		TEST	AL,MASK SEG_CV_TYPES1
		JZ	L65$
		;
		;OK, IT IS TYPES, ARE THEY FROM PRECOMPILED HEADERS?
		;
		MOV	EDX,CURNMOD_GINDEX
		CONVERT	EDX,EDX,MODULE_GARRAY
		ASSUME	EDX:PTR MODULE_STRUCT

		MOV	EAX,CV_TYPES_TYPE 	;TYPE?
		MOV	DL,[EDX]._M_FLAGS

		AND	DL,MASK M_PRECOMPILED_CV
		JZ	L7$
		MOV	EAX,012FH
		JMP	L7$

L65$:
		MOV	EAX,CV_LOCALS_TYPE 	;NOPE, LOCAL SYMBOLS
L7$:
		;
		;WRITE INDEX
		;
		PUSH	ECX
		CALL	WRITE_CV_INDEX

		POP	ECX
		MOV	EAX,BYTES_SO_FAR

		ADD	EAX,ECX

		MOV	BYTES_SO_FAR,EAX
L9$:
		XOR	EAX,EAX
		MOV	HIGH_WATER,EAX
		RET

CV_DATA_FLUSH	ENDP


		.DATA

		ALIGN	4


CV_DATA_PTR	DCA	CV_DATA_FLUSH


CV3_LIST	LABEL	WORD

		DCA	RETT		;CV_MODULES_ALL, SIMPLY RETURN
		DCA	CV_MODULE_3	;
		DCA	CV_LINNUMS_3	;
		DCA	CV_PUBLICS_3	;
		DCA	RETT		;NO SEGTBL OLD CODEVIEW
		DCA	RETT		;HIGH PARA
		DCA	RETT		;DWORD ALIGN
		DCA	RETT		;CV_PUBLICS_ALL
		DCA	RETT		;CV_GLOBALS_ALL
		DCA	RETT		;CV_TYPES_ALL
		DCA	RETT		;CV_STATICS_ALL
		DCA	RETT		;CV_FILES_ALL
		DD	2		;CV INDEX HEADER SIZE (SIMPLY A WORD COUNT)
		DD	FIX2_TARG_TABLE_NORMAL	;
		DD	103H		;TYPES
		DD	104H		;LOCALS
		DD	10		;INDEX SIZE
		DD	106H		;LIBRARY

CV4_LIST	LABEL	WORD

		DCA	RETT		;OUTPUT ALL MODULE INDEXES AT ONCE
		DCA	CV_MODULE_4	;
		DCA	_cv_linnums_4	;
		;DCA	CV_LINNUMS_4	;
		DCA	CV_PUBLICS_4	;
		DCA	CV_SEGTBL_4
		DCA	FINAL_HIGH_PARA
		DCA	_cv_dword_align_rtn
		DCA	RETT		;CV_PUBLICS_ALL
		DCA	RETT		;CV_GLOBALS_ALL
		DCA	RETT		;CV_TYPES_ALL
		DCA	RETT		;CV_STATICS_ALL
		DCA	RETT		;CV_FILES_ALL
		DD	16		;CV_INDEX_HEADER_SIZE
		DD	FIX2_TARG_TABLE_CV	;
		DD	121H		;SSTTYPES
		DD	124H		;SSTSYMBOLS
		DD	12		;INDEX SIZE
		DD	128H		;LIBRARIES

if	fg_cvpack

CV4_PACKED_LIST	LABEL	WORD

		DCA	CV_MODULES_ALL_4;OUTPUT ALL MODULE INDEXES AT ONCE
		DCA	RETT		;NO MODULE INDEXES INDIVIDUALLY
		DCA	_cv_linnums_4	;
		;DCA	CV_LINNUMS_4	;
		DCA	RETT		;NO PUBLICS PER MODULE
		DCA	CV_SEGTBL_4	;
		DCA	FINAL_HIGH_PARA
		DCA	_cv_dword_align_rtn
		DCA	CV_PUBLICS_ALL_4
		DCA	CV_GLOBALS_ALL_4
		DCA	CV_TYPES_ALL_4
		DCA	CV_STATICS_ALL_4
		DCA	CV_FILES_ALL_4	;CV_FILES_ALL
		DD	16		;CV_INDEX_HEADER_SIZE
		DD	FIX2_TARG_TABLE_CV	;
		DD	121H		;SSTTYPES
		DD	124H		;SSTSYMBOLS
		DD	12		;INDEX SIZE
		DD	128H		;LIBRARIES

endif

.DATA?

CV_TABLES		LABEL	WORD

CV_MODULES_ALL		DCA	?
CV_MODULE		DCA	?
CV_LINNUMS		DCA	?
CV_PUBLICS		DCA	?
CV_SEGTBL		DCA	?
CV_FINAL_HIGH_PARA	DCA	?
CV_DWORD_ALIGN		DCA	?
CV_PUBLICS_ALL		DCA	?
CV_GLOBALS_ALL		DCA	?
CV_TYPES_ALL		DCA	?
CV_STATICS_ALL		DCA	?
CV_FILES_ALL		DCA	?
CV_INDEX_HDR_SIZE	DD	?
CV_TARG_TABLE		DD	?
CV_TYPES_TYPE		DD	?
CV_LOCALS_TYPE		DD	?
CV_INDEX_SIZE		DD	?
CV_LIBRARY_TYPE		DD	?

CV_TABLES_LEN		EQU	$-CV_TABLES

			.DATA

			ALIGN	4

CV_PUB_TXT_OFFSET	DD	10
CV_PUB_SYMBOL_ID	DD	103H


		END

